package com.github.shiqiyue.app.api.sapi.controller.app;

/***
 *
 * @author wenyao.wu
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.shiqiyue.app.api.sapi.common.SApiBaseController;
import com.github.shiqiyue.app.api.sapi.req.positionIndex.PositionIndexPageReq;
import com.github.shiqiyue.app.common.req.BasePageReq;
import com.github.shiqiyue.app.common.result.Result;
import com.github.shiqiyue.app.common.result.SimplePageResult;
import com.github.shiqiyue.app.modules.app.entity.CommonIndex;
import com.github.shiqiyue.app.modules.app.entity.PositionIndex;
import com.github.shiqiyue.app.modules.app.service.ICommonIndexService;
import com.github.shiqiyue.app.modules.app.service.IPositionIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sapi/app/positionIndex")
public class SApiPositionIndexController extends SApiBaseController {

    @Autowired
    private IPositionIndexService positionIndexService;

    @PostMapping("page")
    public Result page(PositionIndexPageReq pageReq) {
        QueryWrapper<PositionIndex> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(PositionIndex.Dict.POSITION_ID, pageReq.getPositionId());
        IPage<PositionIndex> resultPage = positionIndexService.page(new Page<>(pageReq.getCurrent(), pageReq.getSize()), queryWrapper);
        SimplePageResult<PositionIndex> result = new SimplePageResult();
        result.setPageInfo(resultPage);
        result.setRecords(resultPage.getRecords());
        return Result.success(result);
    }

    @PostMapping("add")
    public Result add(PositionIndex positionIndex) {
        positionIndexService.save(positionIndex);
        return Result.success();
    }

    @PostMapping("edit")
    public Result edit(PositionIndex positionIndex) {
        positionIndexService.updateById(positionIndex);
        return Result.success();
    }


    @PostMapping("detail")
    public Result detail(Long id) {
        return Result.success(positionIndexService.getById(id));
    }

}
